// $.get("header_menu.html",function(data){ $("#header").html(data); });
$.get("footer.html",function(data){ $("#footer").html(data); });

getData1(1);
$(document).ready(function() {
    // $("#store").addClass("active");
    // $("#store1").addClass("active");

    $('.check1').click(function () {
        getData1(1);
    });
});

function pageDivd(curr,page_num){
    layui.use(['laypage', 'layer'], function(){
        var laypage = layui.laypage
            ,layer = layui.layer;
        laypage.render({
            elem: 'demo7',
            count: page_num,
            limit:5,
            curr:curr,
            jump: function(obj,first){
                if(!first){
                    getData1(obj.curr);

                }
            }
        });
    })
}
function getData1(curr){
    $.ajax({
        type:"get",
        url:"http://114.116.72.220:9999/ShowStores/",
        async:true,
        data:{
            page:curr ,
            row: 5,
            keyword:$("#input1").val()
        },
        success:function(data){
            console.log(data);
            if(data[0].length==0){
                layer.msg('暂无数据');
            }
            TableView(data[0]);
            pageDivd(curr,data[1]);
        }
    });
}
function TableView(data){
    $('#group_table').html('');

    for (var i=0;i<data.length;i++) {
        var trText = `<tr class="${i%2 ? '' : 'tr_back'}">
		      		    
		      		    		<td>${i+1}</td>
		      		    		<td>
		      		    		  <img src="${data[i].store_photo}" alt="">
                                </td>
		      		    		<td>
		      		    			${data[i].store_name}
		      		    		</td>
		      		    		<td>
		      		    			${data[i].store_address}
		      		    		</td>
		      		    		<td>
		      		    			${data[i].store_phone}
		      		    		</td>
		      		    		<td num="${data[i].store_id}">
		      		    			<button class="btn_do look">查看</button>
		      		    			<button class="btn_do del">删除</button>
		      		    		</td>
                        </tr>
		      		    	`;

        $('#group_table').append(trText) ;

    }

    $(".look").click(function () {
        var Index = $(this).parent().attr('num');
        window.location.href="http://114.116.72.220:9010/src/store_detail.html?storeId="+Index;
    });
    $('.del').click(function () {
        var Index = $(this).parent().attr('num');
        $.ajax({
            type: "get",
            url: "http://114.116.72.220:9999/DeleteStore/",
            async: true,
            data: {
                storeId: Index
            },
            success: function (data) {
                console.log(data);
                if (data == 'success') {
                    layer.msg('删除成功', {time: 500}, function () {
                        location.reload();
                    })
                } else {
                    layer.msg('删除失败')
                }

            }

        });
    });

}
